package cn.wd.user.controller;

import cn.wd.common.vo.R;
import cn.wd.user.domain.entity.BulletMsgSensitive;
import cn.wd.user.qo.BulletMsgSensitiveQueryObject;
import cn.wd.user.service.IBulletMsgSensitiveService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/bulletmsgsensitive")
public class BulletMsgSensitiveController {

    private final IBulletMsgSensitiveService service;

    public BulletMsgSensitiveController(IBulletMsgSensitiveService service) {
        this.service = service;
    }

    @RequestMapping("/list")
    public R<Page<BulletMsgSensitive>> query(BulletMsgSensitiveQueryObject qo) {
        return R.OK(service.listBulletMsgSensitivePage(qo));
    }

    @RequestMapping("/all")
    public R<List<BulletMsgSensitive>> all() {
        return R.OK(service.list());
    }

    @RequestMapping("/saveOrUpdate")
    public R<?> saveOrUpdate(@RequestBody BulletMsgSensitive bulletMsgSensitive) {
        if (bulletMsgSensitive.getId() != null) {
            service.updateById(bulletMsgSensitive);
        } else {
            service.save(bulletMsgSensitive);
        }

        return R.OK();
    }

    @RequestMapping("/delete")
    public R<?> delete(Long id) {
        if (id == null) {
            return R.FAIL("删除的 id 不能为空!");
        }

        service.removeById(id);
        return R.OK();
    }
}
